<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>角色管理</title>
    <link rel="stylesheet" href="assets/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
</head>
<body>
<div ng-app="myApp" ng-controller="RoleCtrl">
    <div class="col-md-6">
        <label>菜单配置：</label>&nbsp;&nbsp
        <ui-tree pid-name="pcode" url="system/role/listmenu" check="true" key="menu"></ui-tree>
    </div>
    <ui-form key="roleAdd" column="2">
        <ui-form-input name="name" label="角色名称:"></ui-form-input>
        <ui-form-select name="authorized" label="是否可授权:">
            <option value="0">否</option>
            <option value="1">是</option>
        </ui-form-select>
        <ui-form-textarea name="description" label="描述："></ui-form-textarea>
    </ui-form>
</div>
<script>
    angular.module('myApp', ['ui.form','ui.tree']);
    angular.module('myApp').controller('RoleCtrl', function ($scope) {
        var url = "system/role/add";
        $scope.nodeData = {};
        var defaultTitle = '';
        var defaultPlaceholder = '角色描述...';
        $scope.placeholder = defaultTitle + ' ' + defaultPlaceholder;
        $scope.description = '';
        $scope.focus = function () {
            if (!$scope.description) {
                $scope.description = defaultTitle;
            }
        };

        $scope.blur = function () {
            if ($scope.description === defaultTitle) {
                $scope.description = '';
            }
        };

        $scope.$on('ui.form.submit',function (event,param) {
            var menuTree = $scope['menu'].getCheckedNodes()||[];
            var menuCodes =[];
            for(var i =0 ;i<menuTree.length;i++){
                if(menuTree[i].code != null){
                    menuCodes.push(menuTree[i].code);
                }
            }
            param.menuCodes = menuCodes.join(",");
            $.ajax({
                url:url,
                type:"post",
                data:param
            }).done(function (result) {
                if(result.code == '0000'){
                    toastr.success("新增成功");
                    setTimeout(function () {
                        window.location.href="system/role/index.htm";
                    },1500);
                }else{
                    toastr.error(result.msg);
                }
            }).fail(function (err) {

            });
        })

    });
</script>
<script type="text/javascript" src="assets/ztree/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="assets/ztree/jquery.ztree.excheck.min.js"></script>
<script type="text/javascript" src="assets/ztree/jquery.ztree.exedit.min.js"></script>
</body>
</html>
